//北斗报表

interface IBDNPExportViewModel extends IBaseViewModel<IBDNPExportQueryTerms>{
    /**
     * ui-grid控制
     */
    gridOptions:uiGrid.IGridOptionsOf<LocationListItemResponse>;
    /**
     * 设置高度
     */
    heightA:number;
    
}

interface IBDNPExportQueryTerms{
    /**
     * 定位开始时间
     */
    startTime:string;
    /**
     * 定位结束时间
     */
    endTime:string;
    /**
     * 车牌号
     */
    carCode:string; 
}

class BDNPExportController extends ListController<IBDNPExportViewModel, IBDNPExportQueryTerms>{
    gridApi: uiGrid.IGridApiOf<LocationListItemResponse>;
    constructor($scope:IBDNPExportViewModel,private locationService:ILocationService,private routeService:routeService,private exportService:IexportService,
    private $ngBootbox: BootboxService){
        super($scope);
        this.init();
    }

    init():void{
        super.init();

        this.$scope.queryTerms = {
            startTime:"",
            endTime:"",
            carCode:""
        }

        this.$scope.gridOptions = {
            multiSelect:false,
            enableRowSelection: false,
            enableRowHeaderSelection: false,
            enableSelectAll: false,//全选禁用
            paginationPageSizes: [10, 20, 30],
            useExternalPagination: true,
            useExternalSorting: false,
            enableColumnResizing: true,
            columnDefs: [

                            { displayName: '序号', field: 'index', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, width: '9%' },
                            { displayName: '车牌号', field: 'carCode', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, width: '15%' },
                            { displayName: '定位时间', field: 'locationTime', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, width: '15%' },
                            { displayName: '定位日期', field: 'locationDate', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, width: '15%' },
                            { displayName: '定位位置', field: 'area', enableColumnMenu: false, cellTooltip: true, headerTooltip: true, },


            ],
            onRegisterApi: (gridApi) => {
                this.gridApi = gridApi;
                gridApi.pagination.on.paginationChanged(this.$scope, this.paginationChanged);
            }
        };
        this.query();

        $('#opendataTime').click(function () {
            $('#dataTime').datetimepicker('show');
        });
        $('#opendataTimeEnd').click(function () {
            $('#dataTimeEnd').datetimepicker('show');
        });
    }
    exportFunc=()=>{
        if(this.$scope.gridOptions.totalItems>60000){
            this.$ngBootbox.alert('导出数据不可超过6万条');
            return;
        }else{
            this.exportService.excelBDNPList(this.queryTerms.startTime,this.queryTerms.endTime,this.queryTerms.carCode);
        }
    }

    loadData(queryTerms:IBDNPExportQueryTerms,skip:number,count:number):void{
        this.locationService.getList(queryTerms.startTime,queryTerms.endTime,queryTerms.carCode,skip,count).then(result =>{
            this.$scope.gridOptions.totalItems = result.data.total;
            this.$scope.gridOptions.data = result.data.data;
            /**
             * 设置列表高度
             */
            this.$scope.heightA = (this.$scope.gridOptions.data.length*39) + 80;
            result.data.data.map((item, index) => item.index = skip++ +1);
            if (skip == 0) {
                this.$scope.gridOptions.paginationCurrentPage = 1;
            }
            this.$scope.querying = false;
        }, error => {
            this.$scope.querying = false;
        });
    }
}

angular.module("tms").controller('BDNPExportController',['$scope','locationService','routeService','exportService','$ngBootbox',BDNPExportController]);